﻿
Imports xmlctrl
Imports webctrl
Imports elpmis

Namespace httpFunctions
    'parameters, NA
    'return, var, a new poster control
    Public Class postercreator
        Inherits internalFunction

        Public Class parameters
        End Class

        Public Sub New()
            MyBase.New("poster.create")
        End Sub

        Protected Overrides Function invoke(ByVal ctx As context, ByRef output As bare_variable) As Boolean
            output = New bare_variable(typeDefination.var, currentContext().createControl(New poster()))
            Return True
        End Function
    End Class

    'parameters, same as poster.datasource
    'return, var, a new poster.datasource
    Public Class posterdatasourcecreator
        Inherits internalFunction

        Public Class parameters
            Public Const inputName As String = "inputName"
            Public Const page As String = "page"

            Public Const supportedTagsText As String = "supportedTagsText"
            Public Const defaultValue As String = "defaultValue"

            Public Const imageName As String = "imageName"
            Public Const imageText As String = "imageText"
            Public Const imageImage As String = "imageImage"
            Public Const imageInputTitle As String = "imageInputTitle"

            Public Const urlName As String = "urlName"
            Public Const urlText As String = "urlText"
            Public Const urlImage As String = "urlImage"
            Public Const urlInputTitle As String = "urlInputTitle"

            Public Const mediaName As String = "mediaName"
            Public Const mediaText As String = "mediaText"
            Public Const mediaImage As String = "mediaImage"
            Public Const mediaInputTitle As String = "mediaInputTitle"

            Public Const flashName As String = "flashName"
            Public Const flashText As String = "flashText"
            Public Const flashImage As String = "flashImage"
            Public Const flashInputTitle As String = "flashInputTitle"
        End Class

        Public Sub New()
            MyBase.New("poster.datasource")
        End Sub

        Protected Overrides Function invoke(ByVal ctx As context, ByRef output As bare_variable) As Boolean
            Dim ds As poster.datasource = Nothing
            ds = New poster.datasource()

            ds.inputName = ctx.findVariableStr(parameters.inputName)
            ds.page = ctx.findVariable(Of xhtmlpage)(parameters.page)

            ds.supportedTagsText = ctx.findVariableStr(parameters.supportedTagsText)
            ds.defaultValue = ctx.findVariableStr(parameters.defaultValue)

            ds.imageName = ctx.findVariableStr(parameters.imageName)
            ds.imageText = ctx.findVariableStr(parameters.imageText)
            ds.imageImage = ctx.findVariableStr(parameters.imageImage)
            ds.imageInputTitle = ctx.findVariableStr(parameters.imageInputTitle)

            ds.urlName = ctx.findVariableStr(parameters.urlName)
            ds.urlText = ctx.findVariableStr(parameters.urlText)
            ds.urlImage = ctx.findVariableStr(parameters.urlImage)
            ds.urlInputTitle = ctx.findVariableStr(parameters.urlInputTitle)

            ds.mediaName = ctx.findVariableStr(parameters.mediaName)
            ds.mediaText = ctx.findVariableStr(parameters.mediaText)
            ds.mediaImage = ctx.findVariableStr(parameters.mediaImage)
            ds.mediaInputTitle = ctx.findVariableStr(parameters.mediaInputTitle)

            ds.flashName = ctx.findVariableStr(parameters.flashName)
            ds.flashText = ctx.findVariableStr(parameters.flashText)
            ds.flashImage = ctx.findVariableStr(parameters.flashImage)
            ds.flashInputTitle = ctx.findVariableStr(parameters.flashInputTitle)

            output = New bare_variable(typeDefination.var, ds)
            Return True
        End Function
    End Class

    'parameters, poster, a poster
    '            ds, a datasource created by web.poster.datasource
    'return, bool, success or not
    Public Class postersetdata
        Inherits internalFunction

        Public Class parameters
            Public Const poster As String = "poster"
            Public Const ds As String = "ds"
        End Class

        Public Sub New()
            MyBase.New("poster.setdata")
        End Sub

        Protected Overrides Function invoke(ByVal ctx As context, ByRef output As bare_variable) As Boolean
            Dim poster As poster = Nothing
            If Not ctx.findVariable(Of poster)(parameters.poster, poster) Then
                raiseError("expect parameter " + parameters.poster + " is an instance of poster.", _
                           errorHandle.errorType.user)
                Return False
            Else
                Dim ds As poster.datasource = Nothing
                If Not ctx.findVariable(Of poster.datasource)(parameters.ds, ds) Then
                    raiseError("expect parameter " + parameters.ds + " is an instance of poster.datasource.", _
                               errorHandle.errorType.user)
                    Return False
                Else
                    poster.setData(ds)
                    output = New bare_variable(typeDefination.bool, True)
                    Return True
                End If
            End If
        End Function
    End Class

    'parameters, N/A
    'return, var, a posterViewer instance
    Public Class posterviewercreator
        Inherits internalFunction

        Public Class parameters
        End Class

        Public Sub New()
            MyBase.New("posterViewer.create")
        End Sub

        Protected Overrides Function invoke(ByVal ctx As context, ByRef output As bare_variable) As Boolean
            output = New bare_variable(typeDefination.var, currentContext().createControl(New posterViewer()))
            Return True
        End Function
    End Class

    'parameters, same as posterViewer.datasource
    '            isIEUserAgent will use the value in httpContext
    'return, var, a posterViewer.datasource
    Public Class posterviewerdatasourcecreator
        Inherits internalFunction

        Public Class parameters
            Public Const page As String = "page"
            Public Const text As String = "text"
        End Class

        Public Sub New()
            MyBase.New("posterViewer.datasource")
        End Sub

        Protected Overrides Function invoke(ByVal ctx As context, ByRef output As bare_variable) As Boolean
            Dim ds As posterViewer.datasource = Nothing
            ds = New posterViewer.datasource()

            ds.page = ctx.findVariable(Of xhtmlpage)(parameters.page)
            ds.text = ctx.findVariableStr(parameters.text)

            output = New bare_variable(typeDefination.var, ds)
            Return True
        End Function
    End Class

    'parameters, posterViewer, an instance of posterViewer
    '            ds, an instance of posterViewer.datasource
    'return, bool, success or not
    Public Class posterviewersetdata
        Inherits internalFunction

        Public Class parameters
            Public Const posterViewer As String = "posterViewer"
            Public Const ds As String = "ds"
        End Class

        Public Sub New()
            MyBase.New("posterViewer.setdata")
        End Sub

        Protected Overrides Function invoke(ByVal ctx As context, ByRef output As bare_variable) As Boolean
            Dim i As posterViewer = Nothing
            If Not ctx.findVariable(Of posterViewer)(parameters.posterViewer, i) Then
                raiseError("expect parameter " + parameters.posterViewer + " is an instance of posterViewer.", _
                           errorHandle.errorType.user)
                Return False
            Else
                Dim ds As posterViewer.datasource = Nothing
                If Not ctx.findVariable(Of posterViewer.datasource)(parameters.ds, ds) Then
                    raiseError("expect parameter " + parameters.ds + " is an instance of posterViewer.datasource.", _
                               errorHandle.errorType.user)
                    Return False
                Else
                    i.setData(ds)
                    output = New bare_variable(typeDefination.bool, True)
                    Return True
                End If
            End If
        End Function
    End Class
End Namespace
